import math


def isPrime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return 0
    return n


num = input()

if len(num) != 4:
    print(0)
    exit()

n1 = num[0]
n2 = num[1]
n3 = num[2]
n4 = num[3]

n12 = n1 + n2
n13 = n1 + n3
n14 = n1 + n4
n23 = n2 + n3
n24 = n2 + n4
n34 = n3 + n4

n123 = n1 + n2 + n3
n124 = n1 + n2 + n4
n134 = n1 + n3 + n4
n234 = n2 + n3 + n4

if isPrime(int(num)) != 0:
    print(num)
else:
    MaxPrime = max(isPrime(int(n123)), isPrime(int(n124)), isPrime(int(n134)), isPrime(int(n234)))
    if MaxPrime != 0:
        print(MaxPrime)
    else:
        MaxPrime = max(isPrime(int(n12)),
                       isPrime(int(n13)),
                       isPrime(int(n14)),
                       isPrime(int(n23)),
                       isPrime(int(n24)),
                       isPrime(int(n34)))
        if MaxPrime != 0:
            print(MaxPrime)
        else:
            MaxPrime = max(isPrime(int(n1)), isPrime(int(n2)), isPrime(int(n3)), isPrime(int(n4)))
            print(MaxPrime)